package com.dz.tool.Controller;

import com.dz.tool.Dao.Master.MasterOracleMapper;
import com.dz.tool.Service.MysqlServer;
import com.dz.tool.Service.OracleServer;
import com.dz.tool.Service.SQLServerServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "tool")
public class ToolsController {

    final
    MysqlServer mysqlServer;
    final
    OracleServer oracleServer;
    final
    SQLServerServer sqlServerServer;
    @Autowired
    MasterOracleMapper masterOracleMapper;

    public ToolsController(MysqlServer mysqlServer, OracleServer oracleServer, SQLServerServer sqlServerServer) {
        this.mysqlServer = mysqlServer;
        this.oracleServer = oracleServer;
        this.sqlServerServer = sqlServerServer;
    }

    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {
        List<String> strings = new ArrayList<>();
        mysqlServer.MysqlToExcel(response,strings);
//        oracleServer.OracleToSqlToExcel(response);
    }

    @GetMapping("/sqlTool")
    public List<Map<String, Object>> export(String sql) throws IOException {
        System.out.println(sql);
        List<Map<String, Object>> mapList = masterOracleMapper.creatOracleMap(sql);
        return mapList;
    }


}
